package com.kzw.core.security;

import java.util.Map;
import java.util.Set;

import com.kzw.oa.model.system.AppRole;
import com.kzw.oa.service.system.AppRoleService;

public class SecurityDataSource {

	private AppRoleService appRoleService;

	public void setAppRoleService(AppRoleService appRoleService) {
		this.appRoleService = appRoleService;
	}

	/**
	 * 匿名访问的URLs
	 */
	private Set<String> anonymousUrls = null;
	/**
	 * 登录访问的共公URLs
	 */
	private Set<String> publicUrls = null;

	public SecurityDataSource() {

	}

	public Set<String> getAnonymousUrls() {
		return anonymousUrls;
	}

	public void setAnonymousUrls(Set<String> anonymousUrls) {
		this.anonymousUrls = anonymousUrls;
	}

	public Set<String> getPublicUrls() {
		return publicUrls;
	}

	public void setPublicUrls(Set<String> publicUrls) {
		this.publicUrls = publicUrls;
	}

	/**
	 * 取得安全匹配的数据源,可以考虑其他数据结构，HashMap总来说还不是最好， 相对来说，它的查找速度还是可以。
	 * 
	 * @return
	 */
	public Map<String, Set<String>> getDataSource() {
		Map<String, Set<String>> tmap = appRoleService.getSecurityDataSource();
		tmap.put(AppRole.ROLE_ANONYMOUS, anonymousUrls);
		tmap.put(AppRole.ROLE_PUBLIC, publicUrls);
		return tmap;
	}
}
